package com.dream.technology.utils;


import org.apache.commons.lang3.StringUtils;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;

/**
 * 描述：
 *
 * @author chen_q_i@163.com
 * 2019/1/23 : 17:02.
 * @version : 1.0
 */
public class ZYStringUtils {


    /**
     * 首字母大写
     * @returnir
     */
    public static String toUpperFst(String str) {
        char[] chars = str.toCharArray();
        if (chars[0] >= 'a' && chars[0] <= 'z') {
            chars[0] = (char)(chars[0] - 32);
        }

        return new String(chars);
    }



    //首字母转小写
    public static String toLowerCaseFirstOne(String s){
        if(Character.isLowerCase(s.charAt(0))) {
            return s;
        } else {
            return String.valueOf(Character.toLowerCase(s.charAt(0))) + s.substring(1);
        }
    }


    //首字母转大写
    public static String toUpperCaseFirstOne(String s){
        if(Character.isUpperCase(s.charAt(0))) {
            return s;
        } else {
            return String.valueOf(Character.toUpperCase(s.charAt(0))) + s.substring(1);
        }
    }

    public static String arrayToString(int[] candidates){
        HashSet<Integer> hashSet = new HashSet<Integer>(); // 去重
        for (int i = 0; i < candidates.length; i++){
            hashSet.add(candidates[i]);
        }
        Set<Integer> set = new TreeSet(hashSet);            // 利用TreeSet排序
        Integer[] integers = set.toArray(new Integer[]{});

        String result = "";           // 我们排序、去重后的结果数组
        for (int i = 0; i < integers.length; i++){
            if (StringUtils.isEmpty(result)) {
                result =  integers[i]+"";
            } else {
                result = result+","+integers[i];
            }
        }
        return result;
    }

    /**
     * 校验字符串是否为数字
     * @param str
     * @return
     */
    public static boolean isNumeric(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(str).matches();
    }

}
